package lily.phs.vaccination.test;


import lily.phs.database.Constants;
import lily.phs.object.VaccinationCard;
import lily.phs.urh.R;
import lily.phs.vaccination.VaccinationCardView;
import android.database.Cursor;
import android.test.InstrumentationTestCase;
import android.widget.EditText;
import android.widget.RadioButton;

public class testVaccinationCardView extends InstrumentationTestCase implements Constants{
	private EditText et_profile_id,et_vaca_name,et_vaca_sex,et_vaca_born,et_vaca_nation,
			 et_vaca_number_name,et_vaca_child_id,et_vaca_born_id,et_vaca_guardian_name,
			 et_vaca_relation,et_vaca_guardian_phone,et_vaca_home_address_county,
			 et_vaca_home_address_village,et_vaca_census_address_province,et_vaca_census_address_city,
			 et_vaca_census_address_county,et_vaca_census_address_village,et_vaca_immigration_time,et_vaca_emigration_time,
			 et_vaca_emigration_reason,et_vaca_vaccine_anomalies_his,et_vaca_contraindication,
			 et_vaca_infect_his,et_vaca_create_card_date,et_vaca_create_card_people;
    private RadioButton rb_vaca_census_address1,rb_vaca_census_address2;
    VaccinationCardView v;
    public void setUp(){
    	VaccinationCard vc=new VaccinationCard(getInstrumentation().getContext());
    	vc.setVaca_profile_id(1234);
    	vc.insertVaccinationCard();
    	v=new VaccinationCardView(getInstrumentation().getContext(),1234);
    	v.findWidget();
    	v.addToView();
    	et_profile_id=(EditText)v.findViewById(R.id.et_vaca_id);
		 et_vaca_name=(EditText)v.findViewById(R.id.et_vaca_name);
		 et_vaca_sex=(EditText)v.findViewById(R.id.et_vaca_sex);
		 et_vaca_born=(EditText)v.findViewById(R.id.et_vaca_born);
		 et_vaca_nation=(EditText)v.findViewById(R.id.et_vaca_nation);
		 et_vaca_number_name=(EditText)v.findViewById(R.id.et_vaca_number_name);
		 et_vaca_child_id=(EditText)v.findViewById(R.id.et_vaca_child_id);
		 et_vaca_born_id=(EditText)v.findViewById(R.id.et_vaca_born_id);
		 et_vaca_guardian_name=(EditText)v.findViewById(R.id.et_vaca_guardian_name);
		 et_vaca_relation=(EditText)v.findViewById(R.id.et_vaca_relation);
		 et_vaca_guardian_phone=(EditText)v.findViewById(R.id.et_vaca_guardian_phone);
		 et_vaca_home_address_county=(EditText)v.findViewById(R.id.et_vaca_home_address_county);
		 et_vaca_home_address_village=(EditText)v.findViewById(R.id.et_vaca_home_address_village);
		 et_vaca_census_address_province=(EditText)v.findViewById(R.id.et_vaca_census_address_province);
		 et_vaca_census_address_city=(EditText)v.findViewById(R.id.et_vaca_census_address_city);
		 et_vaca_census_address_county=(EditText)v.findViewById(R.id.et_vaca_census_address_county);
		 et_vaca_census_address_village=(EditText)v.findViewById(R.id.et_vaca_census_address_village);
		 et_vaca_immigration_time=(EditText)v.findViewById(R.id.et_vaca_immigration_time);
		 et_vaca_emigration_time=(EditText)v.findViewById(R.id.et_vaca_emigration_time);
		 et_vaca_emigration_reason=(EditText)v.findViewById(R.id.et_vaca_emigration_reason);
		 et_vaca_vaccine_anomalies_his=(EditText)v.findViewById(R.id.et_vaca_vaccine_anomalies_his);
		 et_vaca_contraindication=(EditText)v.findViewById(R.id.et_vaca_contraindication);
		 et_vaca_infect_his=(EditText)v.findViewById(R.id.et_vaca_infect_his);
		 et_vaca_create_card_date=(EditText)v.findViewById(R.id.et_vaca_create_card_date);
		 et_vaca_create_card_people=(EditText)v.findViewById(R.id.et_vaca_create_card_people);
		 rb_vaca_census_address1=(RadioButton)v.findViewById(R.id.rb_vaca_census_address1);
		 rb_vaca_census_address2=(RadioButton)v.findViewById(R.id.rb_vaca_census_address2);
    }
    public void testData(){
    	Cursor cursor=getInstrumentation().getContext().getContentResolver().query(CONTENT_URI_TB21, null, VACA_PROFILE_ID + "=" + 1234 + ""
    			, null, null);
    	assertEquals(1,cursor.getCount());
    //	cursor.close();
    	
    }
    public void testEditText(){
    	v.selectData();
    	v.initVaccinationCard();
    	assertEquals(et_vaca_sex.getText().toString(),"");
    	assertEquals(et_vaca_born.getText().toString(),"");
    	assertEquals(et_vaca_nation.getText().toString(),"");
    	assertEquals(et_vaca_number_name.getText().toString(),"");
    	assertEquals(et_vaca_child_id.getText().toString(),"");
    	assertEquals(et_vaca_born_id.getText().toString(),"");
    	assertEquals(et_vaca_guardian_name.getText().toString(),"");
    	assertEquals(et_vaca_relation.getText().toString(),"");
    	assertEquals(et_vaca_guardian_phone.getText().toString(),"");
    	assertEquals(et_vaca_home_address_county.getText().toString(),"");
    	assertEquals(et_vaca_home_address_village.getText().toString(),"");
    	assertEquals(et_vaca_census_address_province.getText().toString(),"");
    	assertEquals(et_vaca_census_address_city.getText().toString(),"");
    	assertEquals(et_vaca_census_address_county.getText().toString(),"");
    	assertEquals(et_vaca_census_address_village.getText().toString(),"");
    	assertEquals(et_vaca_immigration_time.getText().toString(),"");
    	assertEquals(et_vaca_emigration_time.getText().toString(),"");
    	assertEquals(et_vaca_emigration_reason.getText().toString(),"");
    	assertEquals(et_vaca_vaccine_anomalies_his.getText().toString(),"");
    	assertEquals(et_vaca_contraindication.getText().toString(),"");
    	assertEquals(et_vaca_infect_his.getText().toString(),"");
    	assertEquals(et_vaca_create_card_date.getText().toString(),"");
    	assertEquals(et_vaca_create_card_people.getText().toString(),"");
    	v.saveVaccinationCard();
    	v.selectData();
    	v.initVaccinationCard();
    	assertEquals(et_vaca_sex.getText().toString(),"");
    	assertEquals(et_vaca_born.getText().toString(),"");
    	assertEquals(et_vaca_nation.getText().toString(),"");
    	assertEquals(et_vaca_number_name.getText().toString(),"");
    	assertEquals(et_vaca_child_id.getText().toString(),"");
    	assertEquals(et_vaca_born_id.getText().toString(),"");
    	assertEquals(et_vaca_guardian_name.getText().toString(),"");
    	assertEquals(et_vaca_relation.getText().toString(),"");
    	assertEquals(et_vaca_guardian_phone.getText().toString(),"");
    	assertEquals(et_vaca_home_address_county.getText().toString(),"");
    	assertEquals(et_vaca_home_address_village.getText().toString(),"");
    	assertEquals(et_vaca_census_address_province.getText().toString(),"");
    	assertEquals(et_vaca_census_address_city.getText().toString(),"");
    	assertEquals(et_vaca_census_address_county.getText().toString(),"");
    	assertEquals(et_vaca_census_address_village.getText().toString(),"");
    	assertEquals(et_vaca_immigration_time.getText().toString(),"");
    	assertEquals(et_vaca_emigration_time.getText().toString(),"");
    	assertEquals(et_vaca_emigration_reason.getText().toString(),"");
    	assertEquals(et_vaca_vaccine_anomalies_his.getText().toString(),"");
    	assertEquals(et_vaca_contraindication.getText().toString(),"");
    	assertEquals(et_vaca_infect_his.getText().toString(),"");
    	assertEquals(et_vaca_create_card_date.getText().toString(),"");
    	assertEquals(et_vaca_create_card_people.getText().toString(),"");
    //	et_profile_id.setText("1");
    //	et_vaca_name.setText("1");
    	et_vaca_sex.setText("1");
    	et_vaca_born.setText("1");
    	et_vaca_nation.setText("1");
		 et_vaca_number_name.setText("1");
		 et_vaca_child_id.setText("1");
		 et_vaca_born_id.setText("1");
		 et_vaca_guardian_name.setText("1");
		 et_vaca_relation.setText("1");
		 et_vaca_guardian_phone.setText("1");
		 et_vaca_home_address_county.setText("1");
		 et_vaca_home_address_village.setText("1");
		 rb_vaca_census_address2.performClick();
		 et_vaca_census_address_province.setText("1");
		 rb_vaca_census_address2.performClick();
		 et_vaca_census_address_city.setText("1");
		 rb_vaca_census_address2.performClick();
		 et_vaca_census_address_county.setText("1");
		 rb_vaca_census_address2.performClick();
		 et_vaca_census_address_village.setText("1");
		 et_vaca_immigration_time.setText("1");
		 et_vaca_emigration_time.setText("1");
		 et_vaca_emigration_reason.setText("1");
		 et_vaca_vaccine_anomalies_his.setText("1");
		 et_vaca_contraindication.setText("1");
		 et_vaca_infect_his.setText("1");
		 et_vaca_create_card_date.setText("1");
		 et_vaca_create_card_people.setText("1");
		 v.saveVaccinationCard();
		 
	    	
	    //	et_profile_id.setText("");
	    //	et_vaca_name.setText("");
	    	et_vaca_sex.setText("");
	    	et_vaca_born.setText("");
	    	et_vaca_nation.setText("");
			 et_vaca_number_name.setText("");
			 et_vaca_child_id.setText("");
			 et_vaca_born_id.setText("");
			 et_vaca_guardian_name.setText("");
			 et_vaca_relation.setText("");
			 et_vaca_guardian_phone.setText("");
			 et_vaca_home_address_county.setText("");
			 et_vaca_home_address_village.setText("");
			 et_vaca_census_address_province.setText("");
			 et_vaca_census_address_city.setText("");
			 et_vaca_census_address_county.setText("");
			 et_vaca_census_address_village.setText("");
			 et_vaca_immigration_time.setText("");
			 et_vaca_emigration_time.setText("");
			 et_vaca_emigration_reason.setText("");
			 et_vaca_vaccine_anomalies_his.setText("");
			 et_vaca_contraindication.setText("");
			 et_vaca_infect_his.setText("");
			 et_vaca_create_card_date.setText("");
			 et_vaca_create_card_people.setText("");
			 assertEquals(et_vaca_sex.getText().toString(),"");
		    	assertEquals(et_vaca_born.getText().toString(),"");
		    	assertEquals(et_vaca_nation.getText().toString(),"");
		    	assertEquals(et_vaca_number_name.getText().toString(),"");
		    	assertEquals(et_vaca_child_id.getText().toString(),"");
		    	assertEquals(et_vaca_born_id.getText().toString(),"");
		    	assertEquals(et_vaca_guardian_name.getText().toString(),"");
		    	assertEquals(et_vaca_relation.getText().toString(),"");
		    	assertEquals(et_vaca_guardian_phone.getText().toString(),"");
		    	assertEquals(et_vaca_home_address_county.getText().toString(),"");
		    	assertEquals(et_vaca_home_address_village.getText().toString(),"");
		    	assertEquals(et_vaca_census_address_province.getText().toString(),"");
		    	assertEquals(et_vaca_census_address_city.getText().toString(),"");
		    	assertEquals(et_vaca_census_address_county.getText().toString(),"");
		    	assertEquals(et_vaca_census_address_village.getText().toString(),"");
		    	assertEquals(et_vaca_immigration_time.getText().toString(),"");
		    	assertEquals(et_vaca_emigration_time.getText().toString(),"");
		    	assertEquals(et_vaca_emigration_reason.getText().toString(),"");
		    	assertEquals(et_vaca_vaccine_anomalies_his.getText().toString(),"");
		    	assertEquals(et_vaca_contraindication.getText().toString(),"");
		    	assertEquals(et_vaca_infect_his.getText().toString(),"");
		    	assertEquals(et_vaca_create_card_date.getText().toString(),"");
		    	assertEquals(et_vaca_create_card_people.getText().toString(),"");
		    	v.selectData();
				 v.initVaccinationCard();
				    assertEquals(et_vaca_sex.getText().toString(),"1");
			    	assertEquals(et_vaca_born.getText().toString(),"1");
			    	assertEquals(et_vaca_nation.getText().toString(),"1");
			    	assertEquals(et_vaca_number_name.getText().toString(),"1");
			    	assertEquals(et_vaca_child_id.getText().toString(),"1");
			    	assertEquals(et_vaca_born_id.getText().toString(),"1");
			    	assertEquals(et_vaca_guardian_name.getText().toString(),"1");
			    	assertEquals(et_vaca_relation.getText().toString(),"1");
			    	assertEquals(et_vaca_guardian_phone.getText().toString(),"1");
			    	assertEquals(et_vaca_home_address_county.getText().toString(),"1");
			    	assertEquals(et_vaca_home_address_village.getText().toString(),"1");
			    	rb_vaca_census_address2.performClick();
			    	assertEquals(et_vaca_census_address_province.getText().toString(),"1");
			    	rb_vaca_census_address2.performClick();
			    	assertEquals(et_vaca_census_address_city.getText().toString(),"1");
			    	rb_vaca_census_address2.performClick();
			    	assertEquals(et_vaca_census_address_county.getText().toString(),"1");
			    	rb_vaca_census_address2.performClick();
			    	assertEquals(et_vaca_census_address_village.getText().toString(),"1");
			    	assertEquals(et_vaca_immigration_time.getText().toString(),"1");
			    	assertEquals(et_vaca_emigration_time.getText().toString(),"1");
			    	assertEquals(et_vaca_emigration_reason.getText().toString(),"1");
			    	assertEquals(et_vaca_vaccine_anomalies_his.getText().toString(),"1");
			    	assertEquals(et_vaca_contraindication.getText().toString(),"1");
			    	assertEquals(et_vaca_infect_his.getText().toString(),"1");
			    	assertEquals(et_vaca_create_card_date.getText().toString(),"1");
			    	assertEquals(et_vaca_create_card_people.getText().toString(),"1");  	
			    	
			    //	et_profile_id.setText("1");
			    //	et_vaca_name.setText("1");
			    	et_vaca_sex.setText("1");
			    	et_vaca_born.setText("1");
			    	et_vaca_nation.setText("1");
					 et_vaca_number_name.setText("1");
					 et_vaca_child_id.setText("1");
					 et_vaca_born_id.setText("1");
					 et_vaca_guardian_name.setText("1");
					 et_vaca_relation.setText("1");
					 et_vaca_guardian_phone.setText("1");
					 et_vaca_home_address_county.setText("1");
					 et_vaca_home_address_village.setText("1");
					// rb_vaca_census_address2.performClick();
					 et_vaca_census_address_province.setText("1");
					// rb_vaca_census_address2.performClick();
					 et_vaca_census_address_city.setText("1");
					// rb_vaca_census_address2.performClick();
					 et_vaca_census_address_county.setText("1");
					// rb_vaca_census_address2.performClick();
					 et_vaca_census_address_village.setText("1");
					 et_vaca_immigration_time.setText("1");
					 et_vaca_emigration_time.setText("1");
					 et_vaca_emigration_reason.setText("1");
					 et_vaca_vaccine_anomalies_his.setText("1");
					 et_vaca_contraindication.setText("1");
					 et_vaca_infect_his.setText("1");
					 et_vaca_create_card_date.setText("1");
					 et_vaca_create_card_people.setText("1");
			    	v.saveVaccinationCard();
			    //	et_profile_id.setText("");
			    //	et_vaca_name.setText("");
			    	et_vaca_sex.setText("");
			    	et_vaca_born.setText("");
			    	et_vaca_nation.setText("");
					 et_vaca_number_name.setText("");
					 et_vaca_child_id.setText("");
					 et_vaca_born_id.setText("");
					 et_vaca_guardian_name.setText("");
					 et_vaca_relation.setText("");
					 et_vaca_guardian_phone.setText("");
					 et_vaca_home_address_county.setText("");
					 et_vaca_home_address_village.setText("");
					 et_vaca_census_address_province.setText("");
					 et_vaca_census_address_city.setText("");
					 et_vaca_census_address_county.setText("");
					 et_vaca_census_address_village.setText("");
					 et_vaca_immigration_time.setText("");
					 et_vaca_emigration_time.setText("");
					 et_vaca_emigration_reason.setText("");
					 et_vaca_vaccine_anomalies_his.setText("");
					 et_vaca_contraindication.setText("");
					 et_vaca_infect_his.setText("");
					 et_vaca_create_card_date.setText("");
					 et_vaca_create_card_people.setText("");
					 assertEquals(et_vaca_sex.getText().toString(),"");
				    	assertEquals(et_vaca_born.getText().toString(),"");
				    	assertEquals(et_vaca_nation.getText().toString(),"");
				    	assertEquals(et_vaca_number_name.getText().toString(),"");
				    	assertEquals(et_vaca_child_id.getText().toString(),"");
				    	assertEquals(et_vaca_born_id.getText().toString(),"");
				    	assertEquals(et_vaca_guardian_name.getText().toString(),"");
				    	assertEquals(et_vaca_relation.getText().toString(),"");
				    	assertEquals(et_vaca_guardian_phone.getText().toString(),"");
				    	assertEquals(et_vaca_home_address_county.getText().toString(),"");
				    	assertEquals(et_vaca_home_address_village.getText().toString(),"");
				    	assertEquals(et_vaca_census_address_province.getText().toString(),"");
				    	assertEquals(et_vaca_census_address_city.getText().toString(),"");
				    	assertEquals(et_vaca_census_address_county.getText().toString(),"");
				    	assertEquals(et_vaca_census_address_village.getText().toString(),"");
				    	assertEquals(et_vaca_immigration_time.getText().toString(),"");
				    	assertEquals(et_vaca_emigration_time.getText().toString(),"");
				    	assertEquals(et_vaca_emigration_reason.getText().toString(),"");
				    	assertEquals(et_vaca_vaccine_anomalies_his.getText().toString(),"");
				    	assertEquals(et_vaca_contraindication.getText().toString(),"");
				    	assertEquals(et_vaca_infect_his.getText().toString(),"");
				    	assertEquals(et_vaca_create_card_date.getText().toString(),"");
				    	assertEquals(et_vaca_create_card_people.getText().toString(),"");
					 v.selectData();
					 v.initVaccinationCard();
					
						 assertEquals(et_vaca_sex.getText().toString(),"1");
					    	assertEquals(et_vaca_born.getText().toString(),"1");
					    	assertEquals(et_vaca_nation.getText().toString(),"1");
					    	assertEquals(et_vaca_number_name.getText().toString(),"1");
					    	assertEquals(et_vaca_child_id.getText().toString(),"1");
					    	assertEquals(et_vaca_born_id.getText().toString(),"1");
					    	assertEquals(et_vaca_guardian_name.getText().toString(),"1");
					    	assertEquals(et_vaca_relation.getText().toString(),"1");
					    	assertEquals(et_vaca_guardian_phone.getText().toString(),"1");
					    	assertEquals(et_vaca_home_address_county.getText().toString(),"1");
					    	assertEquals(et_vaca_home_address_village.getText().toString(),"1");
					    	assertEquals(et_vaca_census_address_province.getText().toString(),"1");
					    	assertEquals(et_vaca_census_address_city.getText().toString(),"1");
					    	assertEquals(et_vaca_census_address_county.getText().toString(),"1");
					    	assertEquals(et_vaca_census_address_village.getText().toString(),"1");
					    	assertEquals(et_vaca_immigration_time.getText().toString(),"1");
					    	assertEquals(et_vaca_emigration_time.getText().toString(),"1");
					    	assertEquals(et_vaca_emigration_reason.getText().toString(),"1");
					    	assertEquals(et_vaca_vaccine_anomalies_his.getText().toString(),"1");
					    	assertEquals(et_vaca_contraindication.getText().toString(),"1");
					    	assertEquals(et_vaca_infect_his.getText().toString(),"1");
					    	assertEquals(et_vaca_create_card_date.getText().toString(),"1");
					    	assertEquals(et_vaca_create_card_people.getText().toString(),"1"); 
					    	v.selectData();
					    	v.initVaccinationCard();
					    		
    }
    public void testRadioButton(){
    	v.selectData();
    	v.initVaccinationCard();
    	assertEquals(rb_vaca_census_address1.isChecked(),false);
    	assertEquals(rb_vaca_census_address2.isChecked(),false);
    	rb_vaca_census_address1.setChecked(true);
    //	rb_vaca_census_address1.performClick();
    	v.saveVaccinationCard();
    	rb_vaca_census_address1.setChecked(false);
    	assertEquals(rb_vaca_census_address1.isChecked(),false);
    	v.selectData();
    	v.initVaccinationCard();
    	assertEquals(rb_vaca_census_address1.isChecked(),true);
    	rb_vaca_census_address2.setChecked(true);
    //	rb_vaca_census_address2.performClick();
    	v.saveVaccinationCard();
    	rb_vaca_census_address2.setChecked(false);
    	assertEquals(rb_vaca_census_address2.isChecked(),false);
    	v.selectData();
    	v.initVaccinationCard();
    	assertEquals(rb_vaca_census_address2.isChecked(),true);
    	
    	
    	
    }
    public void tearDown(){
		 VaccinationCard n=new VaccinationCard(getInstrumentation().getContext());
			n.deleteVaccinationCard(1234);
	 }
}
